/**
 *  @file: UserKeyTask.h
 *  @author: nwz
 *  @brief: 
 *  @date: 2024��8��1��
 * 
 */

#pragma once
#include <all_header.h>

namespace task {

/*
 *
 */
class UserKeyTask {
public:
	enum class Key : uint8_t {
		ON_OFF = 0, K1,K2,K3,K4
	};
	enum class Event : uint8_t {
		DOWN, UP, CLICK, LONG_CLICK
	};

	typedef struct {
		UserKeyTask::Key id;
		UserKeyTask::Event event;
	} notify_event_t;

	UserKeyTask(LcdTask& lcdTask);
	virtual ~UserKeyTask();

	int init();
	void run_();
	static void run(UserKeyTask *task) {
		task->run_();
	}

	int read(notify_event_t *evt, uint32_t timeout= portMAX_DELAY) {
		return xQueueReceive(queue, evt, pdMS_TO_TICKS(timeout)) ? 0 : -1;
	}
private:
	QueueHandle_t queue;
	uint32_t calculateSleepTick();
	LcdTask& lcdTask;

};

} /* namespace task */
